<template>
    <van-sticky>
        <van-nav-bar title="分类" left-text="返回" left-arrow @click-left="onClickLeft" />
    </van-sticky>
    <div class="box">
        <div class="left">
            <van-sidebar v-model="active">
                <van-sidebar-item v-for="item in fenleiList" :title="item.cat_name" />
            </van-sidebar>
        </div>
        <div class="right">
            <van-grid :column-num="3" v-for="item in fenleiList[active]?.children">
                <van-grid-item v-for="value in item.children" :key="value.cat_id" :icon="value.cat_icon" 
                :text="value.cat_name" @click="good(value.cat_id)" />
            </van-grid>
        </div>
    </div>
</template>

<script setup>
import { ref } from 'vue';
import { useFenleiStore } from '../../store';
import { storeToRefs } from 'pinia';
import { useRouter } from 'vue-router';
const router = new useRouter()
const active = ref(0)
const onClickLeft = () => history.back();
const { fenleiList } = storeToRefs(useFenleiStore())
const { FENLEI } = useFenleiStore()
FENLEI();
const good=(cid)=>{
    router.push({
        path:'/goods',
        query:{
            cid
        }
    })
}
</script>

<style lang="scss" scoped>
.box {
    display: flex;
}

.left {
    width: 100px;

}

.right {
    flex: 1;
}
</style>